<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/ui/timeline_viewport.html">
<link rel="import" href="/tracing/ui/tracks/drawing_container.html">
<link rel="import" href="/tracing/ui/tracks/global_memory_dump_track.html">
<link rel="import" href="/tracing/ui/tracks/memory_dump_track_test_utils.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const Viewport = tr.ui.TimelineViewport;
  const GlobalMemoryDumpTrack = tr.ui.tracks.GlobalMemoryDumpTrack;
  const createTestGlobalMemoryDumps = tr.ui.tracks.createTestGlobalMemoryDumps;

  function instantiateTrack(withVMRegions, withAllocatorDumps,
      expectedTrackCount) {
    const dumps = createTestGlobalMemoryDumps(
        withVMRegions, withAllocatorDumps);

    const div = document.createElement('div');
    const viewport = new Viewport(div);
    const drawingContainer = new tr.ui.tracks.DrawingContainer(viewport);
    Polymer.dom(div).appendChild(drawingContainer);

    const track = new GlobalMemoryDumpTrack(viewport);
    Polymer.dom(drawingContainer).appendChild(track);
    drawingContainer.invalidate();

    track.memoryDumps = dumps;
    this.addHTMLOutput(div);

    const dt = new tr.ui.TimelineDisplayTransform();
    dt.xSetWorldBounds(0, 50, track.clientWidth);
    track.viewport.setDisplayTransformImmediately(dt);

    assert.lengthOf(track.tracks_, expectedTrackCount);
  }

  test('instantiate_dotsOnly', function() {
    instantiateTrack.call(this, false, false, 1);
  });

  test('instantiate_withVMRegions', function() {
    instantiateTrack.call(this, true, false, 2);
  });

  test('instantiate_withMemoryAllocatorDumps', function() {
    instantiateTrack.call(this, false, true, 2);
  });

  test('instantiate_withBoth', function() {
    instantiateTrack.call(this, true, true, 3);
  });
});
</script>
